package com.quanyue.haircut.shop.controller;

import com.quanyue.auto.util.ServiceResult;
import com.quanyue.auto.web.Scope;
import com.quanyue.haircut.domain.constant.UserRole;
import com.quanyue.haircut.domain.entity.Technician;
import com.quanyue.haircut.shop.dto.TechnicianCreate;
import com.quanyue.haircut.shop.dto.TechnicianDetail;
import com.quanyue.haircut.shop.service.TechnicianService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(tags = "技师")
@RestController
@RequestMapping("/api")
public class TechnicianController {
    @Autowired
    private TechnicianService technicianService;

    @ApiOperation(value = "添加技师")
    @Scope(role = UserRole.MANAGER)
    @PostMapping(value = "/technician", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Technician> createTechnician(@RequestBody TechnicianCreate technician) {
        return ServiceResult.success(technicianService.createTechnician(technician));
    }

    @ApiOperation(value = "更新技师")
    @Scope(role = UserRole.MANAGER)
    @PutMapping(value = "/technician", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> updateTechnician(@RequestBody Technician technician) {
        technicianService.updateTechnician(technician);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "删除技师")
    @Scope(role = UserRole.MANAGER)
    @DeleteMapping(value = "/technician", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <Boolean> deleteTechnician(@RequestParam Integer technicianId) {
        technicianService.deleteTechnician(technicianId);
        return ServiceResult.SUCCESS;
    }

    @ApiOperation(value = "技师详情")
    @GetMapping(value = "/technician", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <TechnicianDetail> findOne(@RequestParam Integer technicianId) {
        return ServiceResult.success(technicianService.selectTechnician(technicianId));
    }

    @ApiOperation(value = "技师列表")
    @GetMapping(value = "/technician/{shopId}/{serverId}", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public ServiceResult <List <TechnicianDetail>> findList(@PathVariable Integer shopId,
                                                            @PathVariable Integer serverId) {
        return ServiceResult.success(technicianService.technicianList(shopId, serverId));
    }
}
